<template>
  <div>
    <h1 style="float: left;">所有产品数据</h1>
    <div id="pieReport" style="width: 500px; height: 350px; float: left;margin-top:80px;"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
export default {
  name: "",
  data() {
    return {
      charts: "",
      opinion: ["所有产品库存", "所有产品总卖出"],
      opinionData: [
        { value: 3500, name: "所有产品库存", itemStyle: "#1ab394" },
        { value: 12000, name: "所有产品总卖出", itemStyle: "#79d2c0" },
      ],
    };
  },
  mounted() {
    this.$nextTick(function () {
      this.drawPie("pieReport");
    });
  },
  methods: {
    drawPie(id) {
      this.charts = echarts.init(document.getElementById(id));
      this.charts.setOption({
        tooltip: {
          trigger: "item",
          formatter: "{a}<br/>{b}:{c} ({d}%)",
        },
        legend: {
          bottom: 10,
          left: "center",
          data: this.opinion,
        },
        // 状态
        series: [
          {
            name: "状态",
            type: "pie",
            radius: "65%",
            center: ["50%", "50%"],
            avoidLabelOverlap: false,
            itemStyle: {
              emphasis: {
                //阴影的模糊范围
                shadowBlur: 10,
                // 阴影的横向位移量
                shadowOffsetX: 0,
                // 阴影颜色
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
              color: function (params) {
                //自定义颜色
                var colorList = ["#1ab394", "#999"];
                return colorList[params.dataIndex];
              },
            },
            data: this.opinionData,
          },
        ],
      });
    },
  },
};
</script>
<style scoped>
</style>